package com.zhl.stream7;

import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class StreamTest2 {
    public static void main(String[] args) {
        //1,如何获取List集合的Stream流？
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "Tom", "Jerry", "Mike", "Lucy");
        Stream<String> stream = names.stream();



        //2.如何获取Set集合的Stream流？
        Set<String> set = new HashSet<>();
        Collections.addAll(set, "刘德华", "赵德柱", "蜘蛛精", "德玛西亚", "张学友");
        Stream<String> stream2 = set.stream();
        stream2.filter(s -> s.contains("德")).forEach(s -> System.out.println(s));


        //3.如何获取Map集合的Stream流？
        Map<String, Double> map = new HashMap<>();
        map.put("古力娜扎", 180.5);
        map.put("迪丽热巴", 175.0);
        map.put("马儿扎哈", 190.0);
        map.put("卡尔扎巴", 185.0);
        map.put("杨幂", 170.0);
        Set<Map.Entry<String, Double>> entries= map.entrySet();
        Stream<Map.Entry<String, Double>> kvs = entries.stream();
        kvs.filter(e -> e.getKey().contains("扎")).forEach(e -> System.out.println(e.getKey() + ":" + e.getValue()));


        //4.如何获取数组的Stream流？
        String[]  name2 = {"Tom", "Jerry", "Mike", "Lucy"};
        Stream<String> s1 = Arrays.stream(name2);
        Stream<String> s2 = Stream.of(name2);


    }
}
